$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const config = {
        file_type: {
            "6870000000000401": "质量目标",
            "6870000000000402": "质量计划",
            "6870000000000403": "质量创优",
            "6870000000000404": "质量体系文件",
            "6870000000000405": "质量责任体系",
            "6870000000000406": "其他",
            "6870000000000676": "总体目标",
            "6870000000000677": "年度目标"
        }
    }
    const mstform = $NG.getCmpApi("p_form_zlmugl_m")
    const dgrid1 = $NG.getCmpApi("p_form_zlmugl_d1")

    const saveRules = ['save', 'check']
    saveRules.forEach(el => {
        // 保存校验逻辑
        useBeforeClick(() => {
            const file_lock = true
            const rows = dgrid1.getRows()
            rows.forEach(item => {
                if (item.u_fj) {
                    const file_size = (Number(item.u_fj.split("@")[1]) || 0)
                    if (file_size == 0) {
                        file_lock = false
                    }
                }
            })
            if (!file_lock) {
                $NG.alert("当前又附件未上传，请上传附件！")
                return false
            }
        }, el)
    })



    // 文件类别
    useValuesChange(() => {
        const u_wjlb = mstform.getItem("u_wjlb").getValue()
        const rows = dgrid1.getRows()
        const keysSave = rows.reduce((value, item) => {
            value.push(item.u_mc)
            return value
        }, [])
        if (u_wjlb && u_wjlb.length) {
            let temp = []
            u_wjlb.forEach(item => {
                const key = config.file_type[item]
                if (!keysSave.includes(key)) {
                    temp.push({
                        u_mc: key
                    })
                }
            })
            temp = [...rows,...temp]
            const checkKeys = u_wjlb.reduce((value,item)=>{
                value.push(config.file_type[item])
                return value
            },[])
            temp = temp.filter((el)=>{
                if(checkKeys.includes(el.u_mc)){
                    return true
                }
                return false
            })
            console.log(`检查删除项`,temp);
            // 检查删除项
            dgrid1.clearRows().then(()=>{
                dgrid1.addRows(temp)
            })
        }
    }, "p_form_zlmugl_m.u_wjlb")
})